import java.io.IOException;
import java.util.logging.*;

/**
 * This is the class that creates a SystemAdmin, who has control over the user database.
 * 
 * @author Matt Lee (did the javadoc), Michael Zipp
 * @version 1.1
 *
 */
public class SystemAdmin extends User {
	private static Logger systemAdminLog = Logger.getLogger(SystemAdmin.class.getName());
	
	static{
		ConsoleHandler console = new ConsoleHandler();
		console.setLevel(Level.ALL);
		console.setFormatter(new ThunderDragonHtmlFormatter());
		systemAdminLog.addHandler(console);
		systemAdminLog.setLevel(Level.ALL);
		
		try {
			FileHandler fh = new FileHandler("SystemAdminLog.txt");
			fh.setFormatter(new ThunderDragonHtmlFormatter());
			systemAdminLog.addHandler(fh);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			systemAdminLog.severe("Failure: Security exception thrown " +
					"when trying to create a new handler " +
					"in SystemAdmin.java.");
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			systemAdminLog.severe("Failure: I/O exception thrown" +
					" when trying to create a new handler " +
					"in SystemAdmin.java.");
			e.printStackTrace();
		}
		
	}
	
	public SystemAdmin(String name, String username,
			String password, String address, String phoneNum,
			String email, String age){
		super(name, username, password, address, phoneNum, email, age);
		systemAdminLog.entering(this.getClass().getName(), 
				"SystemAdmin Constructor", new Object[] {name, 
			username, password, address,
			phoneNum, email, age});
		systemAdminLog.exiting(this.getClass().getName(), "SystemAdmin Constructor");
		usertype = "admin";

	}
	
	public SystemAdmin(){
		//super();
		usertype = "admin";
		systemAdminLog.entering(this.getClass().getName(), 
				"SystemAdmin Default Constructor");
		systemAdminLog.exiting(this.getClass().getName(), 
				"SystemAdmin Default Constructor");
	}
	
	public SystemAdmin(User user){
		name = user.name;
		username = user.username;
		password = user.password;
		address = user.address;
		phoneNum = user.phoneNum;
		email = user.email;
		age = user.age;
		usertype = "admin";
	}
	
	/**
	 * Creates a new user in the system.
	 * @param user New user to be added, supplied by the GUI
	 * @param userType Type of the user to be added.
	 */
	public void createUser(User user, int userType){
		UserDatabase.addUser(user, userType);
		systemAdminLog.finest("Called createUser() in class SystemAdmin.");
	}
	
	/**
	 * Removes a user from the system.
	 * @param userName Username of the user to be removed
	 * @param userType Type of the user to be removed
	 */
	public void deleteUser(String userName, int userType){
		UserDatabase.removeUser(userName, userType);
		systemAdminLog.finest("Called deleteUser() in class SystemAdmin.");
	}
	
	/**
	 * Sets a user's password. 
	 * @param user
	 * @param newPassword
	 */
	public void setUserPassword(User user, String newPassword){
		user.setPassword(newPassword);
		systemAdminLog.finest("Called setUserPassword() in class SystemAdmin.");
	}
	
	/**
	 * Locks a user's account.
	 * @param user
	 */
	public void lockAccount(User user){
		user.locked = true;
		systemAdminLog.finest("Called lockAccount() in class SystemAdmin.");
	}
	
	/**
	 * Resets a user's account.
	 * @param user
	 */
	public void resetAccount(User user){
		user.locked = false;
		systemAdminLog.finest("Called resetAccount() in class SystemAdmin.");
	}

	

}
